<template>
    <div class="list-container" ref="listContainer">
        <div class="list-item infinite-list" @click="toListenDetail(item.url)">
            <img class="item-img" :src="item.coverPathSmall">
            <div class="item-text">
                <p class="item-title">{{ item.title }}</p>
                <p class="item-times">
                    <i class="xm-icon" v-if="item.contentType == 1">
                        <img class="xm-img" src="@/assets/images/video.png">
                    </i>
                    <i class="xm-icon" v-if="item.contentType == 2"><img class="xm-img" src="@/assets/images/mp3.png"></i>
                    <span class="sound-count">{{ item.dataCount }}</span>
                    <span>{{ moment(item.releaseAt).format('YYYY-MM-DD') }}</span>
                    <span>更新</span>
                </p>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { defineProps } from 'vue'
import moment from 'moment';
import type { SubjectsModel } from '@/api/listening'


defineProps<{
    // title: string
    item: SubjectsModel
}>()

const toListenDetail = async (url: string) => {
    window.location.href = `https://m.ximalaya.com/revision/subject/category${url}`
}
</script>

<style lang="scss" scoped>
p {
    margin: 0;
    padding: 0;
}

.list-container {

    width: 96%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;

    .list-item {
        width: 96%;
        display: flex;
        align-items: center;
        margin-bottom: 10px;
        border-bottom: 1px solid #ccc;
        margin-left: 4%;

        .item-img {
            width: 70px;
            height: 70px;
            vertical-align: middle;
            margin: 15px 0;
        }

        .item-text {
            flex: 1;
            display: flex;
            flex-direction: column;

            .item-title {
                font-size: 16px;
                font-weight: bold;
                margin-bottom: 10px;
                margin-left: 15px;
                word-break: break-all;
                // 文本超出两行隐藏
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 2;
                overflow: hidden;
                // 文字字体
                font-family: PingFangSC-Medium;
                font-weight: normal;

            }

            .item-times {
                display: flex;
                align-items: center;
                font-size: 12px;
                color: #a3a3ac;
                font-family: PingFangSC-Regular;

                .xm-icon {
                    font-style: normal;

                    margin-left: 10px;
                }

                .xm-img {
                    width: 20px;
                    height: 20px;
                }

                .sound-count {
                    margin-left: 5px;
                    margin-right: 14px;
                }
            }
        }
    }
}

.infinite-list {
    //   height: 300px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.infinite-list .infinite-list-item {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 50px;
    background: var(--el-color-primary-light-9);
    margin: 10px;
    color: var(--el-color-primary);
}

.infinite-list .infinite-list-item+.list-item {
    margin-top: 10px;
}
</style>